package com.czy.owner.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.GoodsListModel;
import com.czy.owner.entity.MyStoreGoodsListTagEntity;
import com.czy.owner.entity.StoreGoodsListTagEntity;
import com.czy.owner.utils.MyLog;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.text.DecimalFormat;

/**
 * Created by wangyang on 2017/12/19.
 */
public class StoreGoodsListTagAdapter extends RecyclerArrayAdapter<MyStoreGoodsListTagEntity> {
    private Context context;
    public StoreGoodsListTagAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {

        return new GoodsListHolder(parent);

    }

    @Override
    public void OnBindViewHolder(BaseViewHolder holder, int position) {
        super.OnBindViewHolder(holder, position);
    }



    class GoodsListHolder extends BaseViewHolder<MyStoreGoodsListTagEntity> {
        private ImageView imgShoppingLike;
        private TextView tvShoppingLikeTitle;
        private TextView tvShoppingLikePayment;
        private TextView tvSells;
        private TextView tvMemberPrice;//会员价
        public GoodsListHolder(ViewGroup parent) {
            super(parent, R.layout.item_shopping_like);
            imgShoppingLike = $(R.id.img_shopping_like);
            tvShoppingLikeTitle = $(R.id.tv_shopping_like_title);
            tvShoppingLikePayment = $(R.id.tv_shopping_like_payment);
            tvSells = $(R.id.tv_sells);
            tvMemberPrice = $(R.id.tv_member_price);
        }

        @Override
        public void setData(MyStoreGoodsListTagEntity data) {
            super.setData(data);
            tvSells.setVisibility(View.GONE);
            tvSells.setText("销量"+data.getGoodsSpecValueSalesCount());
            tvShoppingLikeTitle.setText(data.getGoodsName());
            tvShoppingLikePayment.setText("￥"+String.format("%.2f",data.getPrice()));
            MyLog.e("yang","data.getStoreMemberPrice()=="+data.getStoreMemberPrice());
            if(!TextUtils.isEmpty(data.getStoreMemberPrice())){
                tvMemberPrice.setVisibility(View.VISIBLE);
                tvMemberPrice.setText("￥"+String.format("%.2f",Double.parseDouble(data.getStoreMemberPrice())));
            }else {
                tvMemberPrice.setVisibility(View.GONE);
            }
            GlideUtils.loadImage(context, data.getGoodsLogo(), imgShoppingLike, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            }, R.mipmap.default_icon, R.mipmap.default_icon);
        }
    }


}

